Ccay.Module.define("Ccay.example.ui.igrid.validateFunction",function(page,$S){
	page.ready = function(){
		
		var gridData = [
			{required: "布丁", digits: 23, number: 23.3, range: 29.8, date: "2012-11-11", datetime: "2012-11-11 12:02:00", accept: "xx.jpg", email: "q@q.c", url: "w.com"},
			{required: "沙沙", digits: 22, number: 236.6, range: 900, date: "2012-12-21", datetime: "2012-11-11 12:05:00", accept: "xx.png", email: "q@qqcom", url: "http://www.com"},
			{required: "果冻", digits: 23, number: 23.3, range: 29.8, date: "2012-11-11", datetime: "2012-11-11 12:12:00", accept: "xx.jpg", email: "q@q.c", url: "w.com"},
			{required: "", digits: 22, number: 236.6, range: 900, date: "2012-12-21", datetime: "2012-11-11 12:56:00", accept: "xx.png", email: "q@qqcom", url: "http://www.com"}
		];
		
		var gridParam1 = {
			height: 155,
			editMode: true,
			wrap:true,
			showPager: false,
			weakValid:true,
		    columns: [
		 		{field: 'required', width:110, header: "required", rule: {required: true}},
		 		{field: 'digits', width:70, header: "digits", type: 'integer'},
		 		{field: 'number', width:140, header: "number/min/max", type: 'number', rule: {min: 30, max:90}},
		 		{field: 'range', width:70, header: "range", type: 'number', rule: {range: [40, 80]}},
		 		{field: 'date', width:80, header: "date", type: 'date'},
		 		{field: 'datetime', width:140, header: "datetime/dateHM", type: 'datetime', content: "${#getLastTime(datetime)}"},
		 		{field: 'accept', width:130, header: "accept", rule: {accept: "jpg"}},
		 		{field: 'email', width:140, header: "email/rangelength", rule: {email: true, rangelength: [6, 30]}},
		 		{field: 'url', width:180, header: "url/minlength/maxlength", type: "textarea", rule: {url: true, minlength: 11, maxlength: 50}}
		    ]
		};
		
		var gridParam2 = {
			height: 150,
			editMode: true,
			showPager: false,
			wrap:true,
		    columns: [
		 		{field: 'name', width: 140, header: "required(normal)", rule: {required: true}},
				{field: 'mail', width: 140, header: "required(valid)",  rule: {customRequired: function (value, ruleParams, context) {
					return value ? true : "自定义验证：不为空";
					
				}}}
		    ],
			ajax:{
			   	url: 'services/ccay/demo/student/list/page/15/1/${orderBy}'
			}
		};
		
		$.validator.addMethod("customFunc", function(value, element, params){
			    return (value == 1) ? true : false;
		    }, "与自定义验证不符");
		
		var gridParam3 = {
			height: 150,
			editMode: true,
			showPager: false,
			wrap:true,
		    columns: [
		 		{field: 'name', width: 140, header: "required(normal)", rule: {required:true}},
				{field: 'mail', width: 140, header: "required(valid)",  rule: {required:true,customFunc:true}}
		    ],
			ajax:{
			   	url: 'services/ccay/demo/student/list/page/15/1/${orderBy}'
			}
		};  
		$("#iStudent3").igrid(gridParam3);
			
		$S("#validateFunctionDemo").ccayTab();
		
		getLastTime = function(data){
			return Ccay.Format.toDateBefore(data && data.getUTCTime());
		};
		
		//点击tab头后，才加载数据，只第一次生效
		$S("li[tabid='tab2']").one("click", function () {
			$S("#iStudent1").igrid(gridParam1, gridData);
		});
		
		$S("li[tabid='tab3']").one("click", function () {
			$S("#iStudent2").igrid(gridParam2);
		});
	};
	
	page.openDemo = function(tabId){
		$S("#validateFunctionDemo").getCcayTabManager().selectItem(tabId);
		$S("li[tabid='" + tabId + "']").click();
	};
	
});